package com.example.transaction.controller;

import com.example.transaction.model.TransactionRecord;
import com.example.transaction.service.TransactionRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/transactions")
@RequiredArgsConstructor
public class TransactionRecordController {

    private final TransactionRecordService transactionRecordService;

    @GetMapping("/{transactionId}")
    public ResponseEntity<TransactionRecord> getTransactionRecord(@PathVariable String transactionId) {
        TransactionRecord record = transactionRecordService.getTransactionRecord(transactionId);
        return ResponseEntity.ok(record);
    }

    @GetMapping("/account/{accountNumber}")
    public ResponseEntity<List<TransactionRecord>> getAccountTransactions(@PathVariable String accountNumber) {
        List<TransactionRecord> records = transactionRecordService.getAccountTransactions(accountNumber);
        return ResponseEntity.ok(records);
    }

    @GetMapping
    public ResponseEntity<List<TransactionRecord>> getAllTransactionRecords() {
        List<TransactionRecord> records = transactionRecordService.getAllTransactionRecords();
        return ResponseEntity.ok(records);
    }
}